package info.androidhive.tabsswipe;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ExpandableListView;
import info.androidhive.tabsswipe.adapter.ExpListAdapter;

import java.util.ArrayList;

public class MyCardsFragment extends Fragment {


    @Override
    public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
                             Bundle savedInstanceState) {


        View rootView = inflater.inflate(R.layout.fragment_my_cards, container, false);

        final ExpandableListView listView = (ExpandableListView) rootView.findViewById(R.id.exListView);
        ArrayList<ArrayList<String>> groups = new ArrayList<ArrayList<String>>();
        ArrayList<String> children1 = new ArrayList<String>();
        ArrayList<String> children2 = new ArrayList<String>();
        ArrayList<String> children3 = new ArrayList<String>();
        children1.add("Child_1");
        children1.add("Child_2");
        children1.add("Child_3");
        children1.add("Child_4");
        children1.add("Child_5");
        children1.add("Child_6");
        children1.add("Child_7");
        children1.add("Child_8");
        children1.add("Child_9");
        children1.add("Child_10");
        children1.add("Child_11");
        groups.add(children1);
        children2.add("Child_1");
        children2.add("Child_2");
        groups.add(children2);
        children3.add("Child_1");
        children3.add("Child_2");
        groups.add(children3);
        MainActivity act = (MainActivity) getActivity();
        DisplayMetrics metrics = new DisplayMetrics();
        act.getWindowManager().getDefaultDisplay().getMetrics(metrics);
        int width = metrics.widthPixels;
        listView.setIndicatorBounds(width - width / 5, width);
        ExpListAdapter adapter = new ExpListAdapter(getActivity(), groups);
        listView.setAdapter(adapter);


        final Button btn = (Button) rootView.findViewById(R.id.button);
        btn.setText("Добавить карту");


        View.OnClickListener ocl_btn = new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                MainActivity act = (MainActivity) getActivity();
                act.updateViewPager();

            }
        };
        btn.setOnClickListener(ocl_btn);


        return rootView;
    }
}
